package servlet;
import servlet.Connections;
import java.sql.*;
import java.util.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
 * Servlet implementation class getCityServlet
 */
public class getCityServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    Connections conn=new Connections();
    ResultSet rs=null;
    Statement stmt=null;
    String query,stname,xml;    
    PrintWriter out;
    
    public getCityServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		out=response.getWriter();
		stname=request.getParameter("statename");
		
		try
		{
			stmt=conn.getConnection().createStatement();
   			query="select c.city_name from city c,state s where c.state_id=s.state_id and s.state_name='"+stname+"'";
   			
   			rs=stmt.executeQuery(query);
            xml="<select name='city'><option value='-1'>Select</option>";  
           
                while (rs.next())
                {  
                     xml+="<option>"+rs.getString("city_name")+"</option>";
                }  
                xml+="</select>";
                out.write(xml); 
           }  
           catch(Exception e){  
                e.printStackTrace(); 
           }  
            
            
           
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
